home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / PROGENV / MethodB.C < prev    next >
C/C++ Source or Header  |  1992-07-02  |  8KB  |  332 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "MethodB.h"
  6.  
  7. #include "ET++.h"
  8.  
  9. #include "OrdColl.h"
  10. #include "RegularExp.h"
  11. #include "ClassManager.h"
  12. #include "System.h"
  13. #include "Buttons.h"
  14. #include "Fields.h"
  15. #include "ManyOfCluster.h"
  16. #include "BorderItems.h"
  17.  
  18. #include "EtPeCmdNo.h"
  19. #include "EtPeManager.h"
  20.   
  21. static PeMethodFilterDialog *filter;
  22.  
  23. //---- PeMethodItem -----------------------------------------------------------
  24.  
  25. NewMetaImpl(PeMethodItem, TextItem, (TP(cl), TP(mrp)));
  26.  
  27. PeMethodItem::PeMethodItem(PeMethodReference *m, char *label) 
  28.                 : TextItem(cIdNone, label, gFixedFont, Point(2,1))
  29. {
  30.     mrp= m;
  31. }
  32.  
  33. PeMethodItem::PeMethodItem(Class *cp)
  34.         : TextItem(cIdNone, 0, gFixedFont->WithFace(eFaceBold), Point(2,1))
  35. {
  36.     mrp= 0;
  37.     cl= cp;
  38.     SetFString(FALSE, "Class: %s", cp->Name());
  39. }
  40.  
  41. int PeMethodItem::Line()
  42.     return mrp->Line(); 
  43. }
  44.  
  45. Class *PeMethodItem::GetClass()
  46.     return mrp ? mrp->GetClass() : 0; 
  47. }
  48.  
  49. bool PeMethodItem::IsPublic()
  50. {   
  51.     return mrp->IsPublic(); 
  52. }
  53.  
  54. //---- PeMethodBrowser -----------------------------------------------------------
  55.  
  56. NewMetaImpl(PeMethodBrowser, CollectionView, 
  57.                 (TP(allMethods), TP(filteredMethods), TP(ofClass)));
  58.  
  59. PeMethodBrowser::PeMethodBrowser(EvtHandler *b) 
  60.                     : CollectionView(b, 0, eCVDontStuckToBorder)
  61. {
  62.     allMethods= filteredMethods= 0;
  63.     ofClass= 0;
  64.     SetMinExtent(Point(250, 0));
  65. }
  66.  
  67. PeMethodBrowser::~PeMethodBrowser()
  68. {
  69.     if (allMethods) {
  70.     allMethods->FreeAll();
  71.     SafeDelete(allMethods);
  72.     }
  73. }
  74.  
  75. static Object *AsMethodItem(Object*, Object *op, void*)
  76. {
  77.     PeMethodReference *mr= (PeMethodReference*)op;
  78.     return new PeMethodItem(mr, (char*) mr->Str());
  79. }
  80.  
  81. void PeMethodBrowser::ShowMethodsOf(Class* cp)
  82. {
  83.     SeqCollection *oc= 0, *methodsOfClass;
  84.     
  85.     if (cp != 0) {
  86.     oc= new OrdCollection;
  87.     ofClass= cp;
  88.     for (Class *cl= cp; cl != 0; cl= cl->Super()) {
  89.         oc->Add(new PeMethodItem(cl));
  90.         SeqCollection *methods= 
  91.         Guard(gEtPeManager->LoadMethodsOfClass(cl), SeqCollection);
  92.         if (methods) {
  93.         methodsOfClass= (SeqCollection *) methods->Collect(AsMethodItem);
  94.         oc->AddAll(methodsOfClass);
  95.         SafeDelete(methodsOfClass);
  96.         }
  97.     }
  98.     }
  99.     if (allMethods)
  100.     allMethods->FreeAll();
  101.     SafeDelete(allMethods);
  102.     allMethods= oc;
  103.     SetCollection(allMethods, FALSE);
  104.     UpdateEvent();
  105. }
  106.  
  107. void PeMethodBrowser::SelectMethod(PeMethodReference *mr)
  108. {
  109.     PeMethodItem *mi;
  110.     Iter next(GetCollection());
  111.     for (int i= 0; (mi= (PeMethodItem*)next()) != 0; i++) {
  112.     if (mi->mrp && mr->IsEqual(mi->mrp)) {
  113.         Rectangle sr= Rectangle(0, i, 1, 1);
  114.         SetSelection(sr);
  115.         Rectangle r= ItemRect(sr);
  116.         RevealAlign(r);
  117.         return;
  118.     }
  119.     }
  120. }
  121.  
  122. class PeMethodItem *PeMethodBrowser::GetSelectedMethod()
  123. {
  124.     SeqCollection *col= GetCollection();
  125.     if (GetSelection().IsEmpty())
  126.     return 0;
  127.     int at= GetSelection().origin.y;
  128.     PeMethodItem *mi= Guard(col->At(at), PeMethodItem);
  129.     return mi;
  130. }
  131.  
  132. void PeMethodBrowser::DoSelect(Rectangle, int)
  133. {
  134.     PeMethodItem *mi= GetSelectedMethod();
  135.     if (mi == 0)
  136.     return;
  137.     if (mi->mrp != 0) 
  138.     Control(cPeMethodBrowser, cPeChangedMethod, mi->mrp); 
  139.     else {   
  140.     Control(cPeMethodBrowser, cPeCLChangedClass, mi->cl);
  141.     ClearSelection();
  142.     }
  143. }
  144.  
  145. void PeMethodBrowser::Filter()
  146. {
  147.     if (filter == 0)
  148.     filter= new PeMethodFilterDialog();
  149.     if (filter->ShowOnWindow(GetWindow()) == cIdYes) {
  150.     SeqCollection *fp= filter->DoIt(allMethods);
  151.     if (fp == 0)
  152.         return;
  153.     SetCollection(fp, FALSE);
  154.     UpdateEvent();
  155.     SafeDelete(filteredMethods);
  156.     filteredMethods= fp;    
  157.     }
  158. }
  159.  
  160. void PeMethodBrowser::RemoveFilter()
  161. {
  162.     if (filteredMethods != 0) {
  163.     SetCollection(allMethods, FALSE);
  164.     SafeDelete(filteredMethods);
  165.     UpdateEvent();
  166.     }
  167. }
  168.  
  169. //---- Implementors -------------------------------------------------------
  170.  
  171. NewMetaImpl0(PeImplementors, CollectionView);
  172.  
  173. PeImplementors::PeImplementors(EvtHandler *b) : CollectionView(b, 0)
  174. {
  175. }
  176.  
  177. void PeImplementors::ShowImplementorsOf(PeMethodReference *mrp, bool subClassesOnly)
  178. {
  179.     SeqCollection *oc= new OrdCollection;
  180.     Class *cl, *acl= mrp->GetClass();
  181.     char *method= (char*)mrp->Str();
  182.     
  183.     Iter next(gClassManager->Iterator());
  184.     while (cl= (Class*)next()) {
  185.     if (subClassesOnly && !(cl->isKindOf(acl) && cl != acl))
  186.         continue;
  187.     Collection *methods= gEtPeManager->LoadMethodsOfClass(cl);
  188.     if (methods) {
  189.         Iter next1(methods);
  190.         PeMethodReference *mr;
  191.         while (mr= (PeMethodReference*)next1()) {
  192.         if (gEtPeManager->SameMethods((char*)mr->Str(), method)) 
  193.             oc->Add(new PeMethodItem(mr, form("%s::%s", cl->Name(), method)));
  194.         else if (gEtPeManager->IsDestructor(method) && gEtPeManager->IsDestructor((char*)mr->Str()))
  195.             oc->Add(new PeMethodItem(mr, form("%s::~%s", cl->Name(), cl->Name())));
  196.         }
  197.     }
  198.     }
  199.     SetCollection(oc);
  200.     UpdateEvent();
  201. }
  202.  
  203. void PeImplementors::ShowInherited(PeMethodReference *mrp)
  204. {
  205.     SeqCollection *oc= new OrdCollection;
  206.     Class *cl, *ofClass= mrp->GetClass();
  207.     char *methodName= (char*)mrp->Str();
  208.     cl= ofClass->Super();
  209.  
  210.     for (; cl != 0; cl= cl->Super()) {
  211.     Collection *methods= cl->GetMethods();
  212.     if (methods == 0) {
  213.         methods= gEtPeManager->LoadMethodsOfClass(cl);
  214.         cl->SetMethods(methods);
  215.     }
  216.     Iter next1(methods);
  217.     PeMethodReference *mr;
  218.     while (mr= (PeMethodReference*)next1()) {
  219.         if (gEtPeManager->SameMethods((char*)mr->Str(), methodName)) 
  220.         oc->Add(new PeMethodItem(mr, form("%s::%s", cl->Name(), methodName)));
  221.         else if (gEtPeManager->IsDestructor(methodName) && gEtPeManager->IsDestructor((char*)mr->Str()))
  222.         oc->Add(new PeMethodItem(mr, form("%s::~%s", cl->Name(), cl->Name())));
  223.     }
  224.     }
  225.     SetCollection(oc);
  226.     UpdateEvent();
  227. }
  228.  
  229. void PeImplementors::DoSelect(Rectangle, int)
  230. {
  231.     SeqCollection *col= GetCollection();
  232.     int at= GetSelection().origin.y;
  233.     PeMethodItem *mi= Guard(col->At(at), PeMethodItem);
  234.     Control(cPeMethodBrowser, cPeChangedMethod, mi->mrp);
  235.     ClearSelection();    
  236. }
  237.  
  238. //---- PeMethodFilterDialog ----------------------------------------------------
  239.  
  240. PeMethodFilterDialog::PeMethodFilterDialog() : Dialog("Method Filter")
  241. {
  242.     rex= new RegularExp;
  243.     hidePublic= hidePrivate= hideProtected= FALSE;    
  244. }
  245.  
  246. VObject *PeMethodFilterDialog::DoMakeContent()
  247. {
  248.     return
  249.     new Matte( 
  250.         new VExpander(gPoint8,
  251.         new TextItem("Filter (regular expression):"),
  252.         pattern= new TextField(cIdFilter, 20),
  253.         new BorderItem("Hide",
  254.             new ManyOfCluster(cIdVisibility, eVObjVBase, gPoint4,
  255.             "public",
  256.             "protected",
  257.             "private",
  258.             0
  259.             )
  260.         ),
  261.         new HBox(Point(20), (VObjAlign)(eVObjVBase|eVObjHEqual),
  262.             new ActionButton(cIdYes, "Apply Filter", TRUE),
  263.             new ActionButton(cIdCancel, "Cancel"),
  264.             0
  265.         ),
  266.         0
  267.         )
  268.     );
  269. }
  270.  
  271. void PeMethodFilterDialog::Control(int id, int p, void *v)
  272. {
  273.     switch (id) {
  274.     
  275.     case cIdVisibility:
  276.     switch(p) {
  277.     case cIdVisibility:
  278.         hidePublic= !hidePublic;
  279.         break;
  280.     case cIdVisibility+1:
  281.         hideProtected= !hideProtected;
  282.         break;
  283.     case cIdVisibility+2:
  284.         hidePrivate= !hidePrivate;
  285.         break;
  286.     }
  287.     break;
  288.      
  289.     default:
  290.     Dialog::Control(id, p, v);
  291.     } 
  292. }
  293.  
  294. SeqCollection *PeMethodFilterDialog::DoIt(Collection *allMethods)
  295. {
  296.     PeMethodItem *mi;
  297.     bool matchAll= FALSE;
  298.     char pat[1000];
  299.     
  300.     pattern->GetString(pat, sizeof pat);
  301.     if (strlen(pat) == 0) 
  302.     matchAll= TRUE;
  303.     else {
  304.     rex->Reset(pat, TRUE);
  305.     if (rex->GetExprState()) {
  306.         ShowAlert(eAlertNote, rex->GetExprState());
  307.         return 0;
  308.     }
  309.     }
  310.     SeqCollection *filteredMethods= new OrdCollection;
  311.     Iter next(allMethods);
  312.     while (mi= (PeMethodItem *)next()) {
  313.     int n, match= 0;
  314.     if (mi->GetClass() == 0) {
  315.         filteredMethods->Add(mi);
  316.         continue;
  317.     }
  318.     if (!matchAll)
  319.         match= rex->SearchForward(mi->AsString(), &n);
  320.     if (matchAll || match != -1) {
  321.         if (mi->IsPublic() && !hidePublic)
  322.         filteredMethods->Add(mi);
  323.         if (!mi->IsPublic() && !hidePrivate)
  324.         filteredMethods->Add(mi);
  325.     }
  326.     }
  327.     return filteredMethods;
  328. }
  329.  
  330.